package com.stk.doublebreak;

import org.andengine.engine.handler.physics.PhysicsHandler;
import org.andengine.entity.primitive.Rectangle;
import org.andengine.opengl.vbo.VertexBufferObjectManager;

public class Core extends Rectangle{
	
	private PhysicsHandler physicsHandler;
	private int screenWidth;
	private int screenHeight;
	private boolean out;

	public Core(float pX, float pY,VertexBufferObjectManager vbom, float speed, int screenWidth, int screenHeight) {
		super(pX, pY, 1, 1, vbom);
		
		this.setAlpha(0f);

		this.physicsHandler = new PhysicsHandler(this);
        this.registerUpdateHandler(this.physicsHandler);
        this.physicsHandler.setVelocity(speed, (speed * screenHeight) / screenWidth );
        
        this.screenWidth =  screenWidth;
        this.screenHeight = screenHeight;
        
	}
	
	@Override
	protected void onManagedUpdate(final float pSecondsElapsed) {
		if(this.getX() > screenWidth + 20 || this.getY() > screenHeight + 20) {
			out = true;
		}
		super.onManagedUpdate(pSecondsElapsed);
	}

	public boolean isOut() {
		return out;
	}

	public void setOut(boolean out) {
		this.out = out;
	}

}
